package com.shop.admin.controller;

import com.shop.admin.orgvo.SchoolOrgGeneralReport;
import com.shop.admin.orgvo.SchoolOrgYearDataVo;
import com.shop.admin.result.ApiResult;
import com.shop.admin.service.*;
import com.shop.admin.utils.PageUtils;
import com.shop.admin.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = {"DataController"},description = "零食报表接口")
@RestController
@RequestMapping("/api/data")
public class DataController {

    @Resource
    private ShopIndentService indentService;

    @Resource
    private ShopGoodsService goodsService;

    @Resource
    private ShopUserService userService;

    @Resource
    private ShopAdminService adminService;

    @GetMapping("/list")
    @ApiOperation(value = "获取盈利，销售，订单总数量，用户数，有效用户数",notes = "传参组织id")
    public ApiResult list(@ApiParam("参数为：orgId") @RequestParam Map<String, Object> params){
        DataVo vos = indentService.queryPageData(params);
        return ApiResult.ok(vos);
    }

    @GetMapping("/ranking")
    @ApiOperation(value = "获取销售排行榜",notes = "组织id(orgId)")
    public ApiResult ranking(@RequestParam Map<String, Object> params){
        List<RankingVo> vos = goodsService.rankingList(params);
        return ApiResult.ok(vos);
    }

//    @GetMapping("/ranking/list")
//    @ApiOperation(value = "获取销售排行榜",notes = "组织id(orgId)")
//    public ApiResult rankingList(@RequestParam Map<String, Object> params){
//        List<RankingVo> vos = goodsService.ranking(params);
//        return ApiResult.ok(vos);
//    }

    @GetMapping("/zation")
    @ApiOperation(value = "获取7天的销售,销售订单量",notes = "组织id(orgId)")
    public ApiResult imageization(@ApiParam("") @RequestParam Map<String, Object> params){
        Map<String, List<Object>> vos = indentService.getImageIzation(params);
        return ApiResult.ok(vos);
    }

    /**
     * 防注入业务
     */
//    @PostMapping("/xss")
//    @ApiOperation(value = "传入用户id,remark",notes = "key")
//    public ApiResult xss(@ApiParam("key") @RequestBody Map<String, Object> params) {
//        if (indentService.deleteByXss(params)>0){
//            return ApiResult.ok("删除成功");
//        }else {
//            return ApiResult.ok("删除失败");
//        }
//    }

    @GetMapping("/count")
    @ApiOperation(value = "获取管理员的配送数量",notes = "无需传参")
    public ApiResult adminCount(@ApiParam("参数为： {\n" +
            "            \"id\": 2,\n" +
            "            \"countVOS\": {\n" +
            "                \"numDay\": 9,\n" +
            "                \"numCount\": 94,\n" +
            "                \"numYesterDay\": 8\n" +
            "            }\n" +
            "        },id:2何晓珑，3黄梓航,4陈浩生,5陶依达") @RequestParam Map<String, Object> params){
        List<AdminCountVo> vos=indentService.getAdminCount(params);
        return ApiResult.ok(vos);
    }


    @GetMapping("/userRanking")
    @ApiOperation(value = "获取用户订单排行榜",notes = "传参：type = Yesterday(昨日),Today(今日),Count(总共),GGbond我不允许你不传")
    public ApiResult userRanking(@RequestParam Map<String, Object> params){
        List<UserRankingVo> vos = indentService.userRanking(params);
        return ApiResult.ok(vos);
    }

    @GetMapping("/adminMail")
    @ApiOperation(value = "邮箱转换",notes = "传参：adminId(2黄，3何，4陈，5陶),receiveEmail(0不接收，1接收)")
    public ApiResult adminMail(@ApiParam("adminId，receiveEmail")@RequestParam("adminId") Integer adminId,@RequestParam("receiveEmail") Integer receiveEmail){
        adminService.adminMailChange(adminId,receiveEmail);
        return ApiResult.ok("更新成功!");
    }

    @GetMapping("/genera/list")
    @ApiOperation(value = "获取盈利，销售，订单总数量，用户数，有效用户数 报表数据",notes = "传参组织id，分页数据")
    public ApiResult schoolOrgGeneralReport (@ApiParam("参数为：orgId,page,limit") @RequestParam Map<String, Object> params){
        PageUtils vos = indentService.schoolOrgGeneralReport(params);
        return ApiResult.ok(vos);
    }

    @GetMapping("/year/proportion")
    @ApiOperation(value = "获取总额销售，总额利润，总数量，今年销售，今年利润，今年数量，去年销售 去年利润,去年数量，销售额对比,利润额对比",notes = "传参组织id")
    public ApiResult schoolOrgYearData (@ApiParam("参数为：orgId") @RequestParam Map<String, Object> params){
        List<SchoolOrgYearDataVo> vos = indentService.schoolOrgYearProportion(params);
        return ApiResult.ok(vos);
    }
}
